﻿<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="css/style.css" />
<link type="text/css" rel="stylesheet" href="css/layout.css" />
<title>Danh sach đơn đặt hàng</title>

<body>
<?php include("menu.php"); 
include("session.php");
include("../include/config.php");
?>
<?php
// $_SESSION['contract']['show']
if(isset($_POST["lst_show"]))
{ 
	$_SESSION['contract']['show'] = $_POST["lst_show"];
}
$str0 = "";
if(isset($_SESSION['contract']['show']))
{
	switch($_SESSION['contract']['show']) 
	{
		case 0: $str0 = "WHERE status = 0";break;
		case 1: $str0 = "WHERE status = 1";break;
		case 2: $str0 = "WHERE status = 2";break;
		case 3: $str0 = "WHERE status = 3";break;
		case 4: $str0 = "WHERE status = 4";break;
		default: $str0 = "WHERE status != 4";
	}
}
else $str0 = "WHERE status != 4";

//$_SESSION['contract']['sort']
if(isset($_REQUEST["sort"]))
{
	$_SESSION['contract']['sort'] = $_REQUEST["sort"];
}
$str1 = "";
if(!isset($_SESSION['contract']['sort']))
{$str1 = "deliver_date desc";}
else
	switch($_SESSION['contract']['sort']) 
	{
		case "sort_by_status_asc": $str1 = "status";break;
		case "sort_by_status_desc": $str1 = "status desc";break;
		case "sort_by_email_asc": $str1 = "email";break;
		case "sort_by_email_desc": $str1 = "email desc";break;
		case "sort_by_price_asc": $str1 = "price";break;
		case "sort_by_price_desc": $str1 = "price desc";break;
		case "sort_by_name_asc": $str1 = "customer_name";break;
		case "sort_by_name_desc": $str1 = "customer_name desc";break;
		case "sort_by_date_asc": $str1 = "deliver_date";break;
		default: $str1 = "deliver_date desc";
	}


if(isset($_POST["lst"]))
{
			  $id_status = $_POST["lst"];
			  $sqldel="DELETE FROM contract WHERE status = $id_status";
			  mysql_query($sqldel);
			  header("Location:contract.php"); 
}

if(isset($_REQUEST["status_select"]))
{
	 $id_edit = $_REQUEST["id"];
	 $id_status = $_REQUEST["status_select"];      
	 $sqldel="UPDATE contract SET status=$id_status WHERE id=$id_edit";
	 mysql_query($sqldel);
	 header("Location:contract.php");
}			
?>

<div id="head-noidung">
		<div id="head-main">		
		<form action = "" method = "post">
			<input name = "change_status" type="image" src="images/status/trash.png" width="20" height="20" style = "float:right;margin:5px"  onclick="return confirm('Ban Chac chan muon xoa Danh Sach Da Chon?');" alt="Submit" />	
			<select name = "lst" style = "float:right;margin:5px;">
				<option value = "2"> Đã Hoàn Thành </option>
				<option value = "3"> Đã Hủy </option>
				<option value = "4"> Lưu Trữ! </option>
			</select>
			<a style = "float:right;margin:5px;">Xóa</a>
		</form>
		<form action = "" method = "post">
			<input name = "change_show" type="image" src="images/status/show.png" width="20" height="20" style = "float:right;margin-top:5px;margin-bottom:5px;margin-top:5px;margin-right:25px;" alt="Submit" />	
			<select name = "lst_show" style = "float:right;margin:5px;">
				<option value = "5" <?php ?> >Tất Cả</option>
				<option value = "0" <?php if(isset($_SESSION['contract']['show']) && $_SESSION['contract']['show'] == 0 ) echo "selected";?>>Chưa xử lý !</option>
				<option value = "1" <?php if(isset($_SESSION['contract']['show']) && $_SESSION['contract']['show'] == 1 ) echo "selected";?>>Đang Thực Hiện</option>
				<option value = "2" <?php if(isset($_SESSION['contract']['show']) && $_SESSION['contract']['show'] == 2 ) echo "selected";?>>Hoàn Thành</option>
				<option value = "3" <?php if(isset($_SESSION['contract']['show']) && $_SESSION['contract']['show'] == 3 ) echo "selected";?>>Đã Hủy</option>
				<option value = "4" <?php if(isset($_SESSION['contract']['show']) && $_SESSION['contract']['show'] == 4 ) echo "selected";?>>Lưu Trữ !</option>					
			</select>
			<a style = "float:right;margin:5px;">Hiển Thị</a>
		</form>
	
	<p>Danh sách đơn đặt hàng</p>
	<table class="classtable">
	<thead>
		<tr>
			<th>STT</th>
			<th><a href = "contract.php?sort=<?php if(isset($_SESSION['contract']['sort'])&&($_SESSION['contract']['sort'] == "sort_by_name_asc")) echo "sort_by_name_desc"; else echo "sort_by_name_asc";  ?>">Khách Hàng</a></th>
			<th>Điện Thoại</th>
			<th><a href = "contract.php?sort=<?php if(isset($_SESSION['contract']['sort'])&&($_SESSION['contract']['sort'] == "sort_by_email_asc")) echo "sort_by_email_desc"; else echo "sort_by_email_asc";  ?>">Email</a></th>
			<th><a href = "contract.php?sort=<?php if(isset($_SESSION['contract']['sort'])&&($_SESSION['contract']['sort'] == "sort_by_price_asc")) echo "sort_by_price_desc"; else echo "sort_by_price_asc";  ?>">Tổng Giá</a></th>
			<th><a href = "contract.php?sort=<?php if(isset($_SESSION['contract']['sort'])&&($_SESSION['contract']['sort'] == "sort_by_date_asc")) echo "sort_by_date_desc"; else echo "sort_by_date_asc";  ?>">Ngày Giao</a></th>
			<th><a href = "contract.php?sort=<?php if(isset($_SESSION['contract']['sort'])&&($_SESSION['contract']['sort'] == "sort_by_status_asc")) echo "sort_by_status_desc"; else echo "sort_by_status_asc";  ?>">Tình Trạng</a></th>
			<th>Thao Tác</th>
		</tr>
	</thead>
	<?php 
	$sql1="SELECT * FROM contract $str0 ORDER by $str1";
	$rs1=mysql_query($sql1);
	if($rs1) {
	 $i=1;
	 
	 while($rw1=mysql_fetch_array($rs1)) {		 
	?>
	<tbody>
	<tr>	
		<td><?php echo $i;?></td>
		<td><?php echo $rw1["customer_name"];?></td>
		<td><?php echo $rw1["phone"];?></td>
		<td><?php echo $rw1["email"];?></td>
		<td><?php echo $rw1["price"];?></td>
		<td><?php echo $rw1["deliver_date"];?></td>
		<td><?php if($rw1["status"]==0) { ?>  <?php } 
				    else {if($rw1["status"]==1) { ?> <img src="images/status/running.png" width="23" height="22"/> <?php } 
					 else {if($rw1["status"]==2) { ?> <img src="images/status/done.png" width="23" height="22"/> <?php } 
					  else {if($rw1["status"]==3) { ?> <img src="images/status/drop.png" width="23" height="22"/> <?php }
					  else { ?>  <?php } } } }?> 
				</td>	
		<form action = "contract.php?id=<?php echo $rw1["id"]; ?>" method = "post" >				
		<td>		
			<select name = "status_select" style = "margin-top:4px;margin-bottom:4px; float:left;">
				<option value = "0" <?php  if($rw1["status"]==0) echo "selected"; ?> >Chưa xử lý !</option>
				<option value = "1" <?php  if($rw1["status"]==1) echo "selected"; ?> >Đang Thực Hiện</option>
				<option value = "2" <?php  if($rw1["status"]==2) echo "selected"; ?> >Hoàn Thành</option>
				<option value = "3" <?php  if($rw1["status"]==3) echo "selected"; ?> >Đã Hủy</option>
				<option value = "4" <?php  if($rw1["status"]==4) echo "selected"; ?> >Lưu Trữ !</option>
			</select>
			<input name = "change_status" type="image" src="images/status/save.png" width="20" height="20" style = "float:left;margin-top:3px;margin-bottom:3px; margin-left:3px;"  alt="Submit" />		
			<a href = "contract_detail.php?id= <?php echo $rw1["id"];?>"><img src="images/status/detail.png" width="20" height="20" style = "float:right;margin-top:3px;margin-bottom:3px;" /></a>
				</td>	
		</form>
	</tr>
	<?php 
	$i+=1;
	}
	} ?>		

		
</tbody>

</table>	
	</div>	
</div>


<?php include("images/cherry/footer.php");?>

</body>
</html>